﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JNPF.Logging
{
    public class LoggEx
    {
        private object _objLock1 = new object();
        private object _objLock2 = new object();
        private object _objLock3 = new object();
        private object _objLock4 = new object();
        private object _objLock5 = new object();
        public void setlog(string str)
        {
            string name = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string rootPath = Directory.GetCurrentDirectory();
            string path = $@"{rootPath}/logs/debug";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lock (_objLock1)
            {
                using (FileStream fs = new FileStream(path + "/" + name, FileMode.Append))
                {
                    str = "\r\n日期：" + DateTime.Now.ToString() + "\r\n消息：" + str;
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(str);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
        
        public void Info(string str)
        {
            string name = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string rootPath = Directory.GetCurrentDirectory();
            string path = $@"{rootPath}/logs/Info";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lock (_objLock2)
            {
                using (FileStream fs = new FileStream(path + "/" + name, FileMode.Append))
                {
                    str = "\r\n日期：" + DateTime.Now.ToString() + "\r\n消息：" + str;
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(str);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
        public void errlog(string str)
        {
            string name = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string rootPath = Directory.GetCurrentDirectory();
            string path = $@"{rootPath}/logs/err";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lock (_objLock3)
            {
                using (FileStream fs = new FileStream(path + "/" + name, FileMode.Append))
                {
                    str = "\r\n日期：" + DateTime.Now.ToString() + "\r\n消息：" + str;
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(str);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
        public void uniEvtlog(string str)
        {
            string name = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string rootPath = Directory.GetCurrentDirectory();
            string path = $@"{rootPath}/logs/uniEvt";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lock (_objLock4)
            {
                using (FileStream fs = new FileStream(path + "/" + name, FileMode.Append))
                {
                    str = "\r\n日期：" + DateTime.Now.ToString() + "\r\n消息：" + str;
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(str);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
        /// <summary>
        /// 数据同步
        /// </summary>
        /// <param name="str"></param>
        public void basicdataSynlog(string str)
        {
            string name = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string rootPath = Directory.GetCurrentDirectory();
            string path = $@"{rootPath}/logs/dataSyn";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lock (_objLock5)
            {
                using (FileStream fs = new FileStream(path + "/" + name, FileMode.Append))
                {
                    str = "\r\n日期：" + DateTime.Now.ToString() + "\r\n消息：" + str;
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(str);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
    }

}
